package com.lzw.bluetoothpractice.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.DetailMyActivity;
import com.lzw.bluetoothpractice.Activitys.EquipmentActivity;
import com.lzw.bluetoothpractice.Activitys.IndexActivity;
import com.lzw.bluetoothpractice.Activitys.MedicalMessage;
import com.lzw.bluetoothpractice.Activitys.MyAttentionActivity;
import com.lzw.bluetoothpractice.Activitys.MyCollectionActivity;
import com.lzw.bluetoothpractice.Activitys.MyDoctorsActivity;
import com.lzw.bluetoothpractice.Activitys.MyFansActivity;
import com.lzw.bluetoothpractice.Activitys.MyForumActivity;
import com.lzw.bluetoothpractice.Activitys.SearchDeviceActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.Utils.SharePreferenceUtils;

import static com.lzw.bluetoothpractice.MyApplication.getContext;


public class MyFragment extends Fragment implements View.OnClickListener {
    View view;
    //定义五个Layout布局
    LinearLayout my_device,my_plan,my_message,my_check,my_attention;
    ImageView imageView;//头像
    TextView name,phone;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view = inflater.inflate(R.layout.activity_my,null);
        init();

        return view;
    }
    //进行初始化
    private void init() {
       // attention=view.findViewById(R.id.attention);
     //   fans=view.findViewById(R.id.fans);
        my_device  = (LinearLayout)view.findViewById(R.id.my_device);
        my_plan = (LinearLayout)view.findViewById(R.id.my_plan);
        my_message = (LinearLayout)view.findViewById(R.id.my_message);
        my_check = (LinearLayout)view.findViewById(R.id.my_check);
        my_attention = (LinearLayout)view.findViewById(R.id.my_attention);
        imageView = (ImageView)view.findViewById(R.id.my_head_id);
        name = (TextView) view.findViewById(R.id.name);
        phone = (TextView) view.findViewById(R.id.phone);

        my_device.setOnClickListener(this);
        my_plan.setOnClickListener(this);
        my_message.setOnClickListener(this);
        my_check.setOnClickListener(this);
        my_attention.setOnClickListener(this);
        imageView.setOnClickListener(this);

        String head = SharePreferenceUtils.getString(getContext(),"Avatar",null);;
        String username = SharePreferenceUtils.getString(getContext(),"username",null);;
        String userphone = SharePreferenceUtils.getString(getContext(),"phone",null);;

        Glide.with(getContext()).load(AppConfig.BASE_URL+head).into(imageView);

        name.setText(username);
        phone.setText(userphone);

    }

    @Override
    public void onClick(View view){
        switch (view.getId()){
            case R.id.my_head_id:
               /* Intent intent1 = new Intent(getActivity(), DetailMyActivity.class);
                startActivity(intent1);*/
                break;
            case R.id.my_plan:
                Intent intent2 = new Intent(getActivity(), IndexActivity.class);
                intent2.putExtra("id",1);
                startActivity(intent2);
                break;
            case R.id.my_message:
                Intent intent3 = new Intent(getActivity(), MyDoctorsActivity.class);
                startActivity(intent3);
                break;
            case R.id.my_check:
                Intent intent4 = new Intent(getActivity(), IndexActivity.class);
                intent4.putExtra("id",2);
                startActivity(intent4);
                break;
            case R.id.my_attention:
                Intent intent5 = new Intent(getActivity(), MyForumActivity.class);
                //intent5.putExtra("id",2);
                startActivity(intent5);
                break;
            case R.id.my_device:
                Intent intent=new Intent(getActivity(), EquipmentActivity.class);
                startActivity(intent);
                break;
          /*  case R.id.attention:
                Intent intent7 = new Intent(getActivity(), MyAttentionActivity.class);
                startActivity(intent7);
                break;
            case R.id.fans:
                Intent intent8 = new Intent(getActivity(), MyFansActivity.class);
                startActivity(intent8);
                break;*/

        }
    }
}
